package com.ohuang.myapp.provider;

import com.ohuang.myapp.ResourceTable;
import com.ohuang.myapp.bean.TieBa;
import ohos.agp.components.*;
import ohos.app.Context;

import java.util.List;

public class ListProvider extends BaseItemProvider {
    private List<TieBa> list;
    private Context context;


    public ListProvider(List<TieBa> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }


    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        component=LayoutScatter.getInstance(context).parse(ResourceTable.Layout_item_text, null, false);
        Text text= (Text) component.findComponentById(ResourceTable.Id_text);
        text.setText(list.get(i).getContent());
        return component;
    }
}
